package com.musiklegal;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class InterfaceAdapter extends BaseAdapter
{
	 
	
	 List<DataSong> list;
	 private Activity activity;
	 private static LayoutInflater inflater=null;
	 
	 
	 ImageLoader imageLoader;
	 
	 public InterfaceAdapter(Activity a,List<DataSong> cat) 
	 {
		 list=cat;
		 activity =a;
		 imageLoader=new ImageLoader();
		 inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	 }
	 
	 public int getCount()
	 {
		 return list.size();
	 }

	public Object getItem(int position)
	{
		 return list.get(position);
	}

	public long getItemId(int position)
	{
		 return position;
	}
	
	 static class ViewHolder {
	 public ImageView imageView;
	 public TextView textView;
	 public TextView textView2;
	 }
	 
	 Handler h;
	 
	 ViewHolder holder;
	 public View getView(final int position, View convertView, ViewGroup parent) {
		
	 
	 
	 View rowView = convertView;
	 if (rowView == null) {
		 rowView = inflater.inflate(R.layout.view,null);
	 	holder = new ViewHolder();
	 	holder.textView = (TextView) rowView.findViewById(R.id.TextView01);
	 	holder.textView2 = (TextView) rowView.findViewById(R.id.TextView02);
	 	holder.imageView = (ImageView) rowView.findViewById(R.id.ImageView01);
	 	rowView.setTag(holder);
	 } 
	 else {
	 holder = (ViewHolder) rowView.getTag();
	 }
	 if(position<list.size())
	 {
		 holder.textView.setText(list.get(position).song);
		 
		 holder.textView2.setText(list.get(position).artist);
		 holder.imageView.setTag(list.get(position).album);
		 imageLoader.DisplayImage(list.get(position).album, activity, holder.imageView,list.get(position).albid);
		
	 }
	 	return rowView;
	 }
	 
	 
	 public void clear()
	 {
		 imageLoader.clearMemory();
	 }
	
	
}

